#!/usr/bin/env python3
"""
气象服务配置文件
"""

import os
from typing import Optional
from datetime import datetime

class WeatherConfig:
    """气象服务配置"""
    
    # Visual Crossing API配置
    VISUAL_CROSSING_API_KEY = os.getenv('VISUAL_CROSSING_API_KEY', 'UA4NZPFNSZ5R7QPSW6AYNZKMY')
    
    # 比利时布鲁塞尔坐标（可代表全国）
    LATITUDE = 50.8503
    LONGITUDE = 4.3517
    BELGIUM_LAT = 50.8503
    BELGIUM_LON = 4.3517
    
    # API请求配置
    REQUEST_TIMEOUT = 30
    MAX_RETRIES = 3
    
    # 数据源配置
    DEFAULT_DATA_SOURCE = 'visualcrossing'
    
    @classmethod
    def get_api_key(cls) -> Optional[str]:
        """获取Visual Crossing API密钥"""
        if cls.VISUAL_CROSSING_API_KEY == 'YOUR_VISUAL_CROSSING_API_KEY':
            return None
        return cls.VISUAL_CROSSING_API_KEY
    
    @classmethod
    def is_api_key_configured(cls) -> bool:
        """检查API密钥是否已配置"""
        return cls.get_api_key() is not None
    
    @classmethod
    def get_weather_source_for_date(cls, target_date: datetime) -> str:
        """获取指定日期的天气数据源（统一使用Visual Crossing）"""
        return 'visualcrossing'
    
    @classmethod
    def get_visualcrossing_config(cls) -> dict:
        """获取Visual Crossing配置"""
        return {
            'api_key': cls.get_api_key(),
            'latitude': cls.LATITUDE,
            'longitude': cls.LONGITUDE,
            'timeout': cls.REQUEST_TIMEOUT,
            'max_retries': cls.MAX_RETRIES
        }
    
    @classmethod
    def get_visualcrossing_api_key(cls) -> Optional[str]:
        """获取Visual Crossing API密钥"""
        return cls.get_api_key()
    
    @classmethod
    def get_openmeteo_config(cls) -> dict:
        """获取OpenMeteo配置（备用）"""
        return {
            'latitude': cls.LATITUDE,
            'longitude': cls.LONGITUDE,
            'timeout': cls.REQUEST_TIMEOUT,
            'max_retries': cls.MAX_RETRIES
        } 